package com.rfid.project.util;

public class StringUtil {
	/**
	 * 截取字符串
	 * @param start 开始位置
	 * @param length 截取长度
	 * @param data 原字符串
	 * @return 截取后的字符串
	 */
	public static String subString(int start, int length, String data){
		if(null == data){
			return "";
		}
		if(data.length() > length - start){
			return data;
		}
		return data.substring(start, start + length);
	}
	
	/**
	 * 获取对象的字符串形式
	 * @param object
	 * @return
	 */
	public static String getString(Object object){
		if(null == object){
			return "";
		}
		return object.toString();
	}
	
	public static String getString(Object object, String chars, int length){
		if(null == object){
			return "";
		}
		String obj = object.toString();
		int index = obj.indexOf(chars);
		if(index < 0){
			return obj;
		}
		if(obj.length() < index + 1 + length){
			return obj;
		}
		StringBuilder builder = new StringBuilder(obj.substring(0, index));
		builder.append(obj.substring(index, index + 1 + length));
		return builder.toString();
	}
}
